//
//  LSZFindOutMoreVC+LCMenu.m
//  JKFuYinProject
//
//  Created by admin on 2018/1/17.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZFindOutMoreVC+LCMenu.h"

@implementation LSZFindOutMoreVC (LCMenu)

- (void)setupNVAndMenu {
    
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60,30)];
    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    UIBarButtonItem *closeBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭"/**Image:[UIImage imageNamed:@"z5"]*/ style:UIBarButtonItemStyleDone target:self action:@selector(close:)];
    self.navigationItem.leftBarButtonItems = @[backBarButtonItem,closeBarButtonItem];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"点点点"] style:UIBarButtonItemStyleDone target:self action:@selector(rightBtnAction)];

}
- (IBAction)back:(UIBarButtonItem *)sender {
    if (self.webView.canGoBack || [PAWebView shareInstance].webView.canGoBack) {
        [self.webView goBack];
        [[PAWebView shareInstance] goback];
    }else{
        [self closeShop];
    }
}
- (void)closeShop{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"LCPAWebViewLoadFail" object:nil];
    self.progressView.hidden = YES;
    [PAWebView shareInstance].view.hidden = YES;
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    if ([PAWebView shareInstance].isloadSuccess == NO) {
        NSString *url = [NSString stringWithFormat:@"%@?%@",shoopLogin,[UserPageManager getUrlStrMove]];
        Reachability *reach = [Reachability reachabilityWithHostName:url];
        if (!([reach currentReachabilityStatus] == NotReachable)){
            [PAWebView shareInstance].link = url;
            [[PAWebView shareInstance] loadRequestURL:[NSURL URLWithString:url]];
        }
    }
    NSArray<WKBackForwardListItem *> *history = [[PAWebView shareInstance].webView.backForwardList backList];//历史记录的列表
    if (history.count > 0) {
        [[PAWebView shareInstance].webView goToBackForwardListItem:history[0]];//跳转想对应网页的操作
    }
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)close:(UIBarButtonItem *)sender {
    [self closeShop];
}
- (void) rightBtnAction {
//    @weakify(self)
    NSMutableArray *mutableArrayTitles = @[@"客服电话"].mutableCopy;
    if ([ShareSDK isClientInstalled:SSDKPlatformTypeQQ] == YES) {
        [mutableArrayTitles insertObject:@"QQ客服" atIndex:0];
    }
    if ([ShareSDK isClientInstalled:SSDKPlatformTypeWechat] == YES) {
        [mutableArrayTitles insertObject:@"微信客服" atIndex:0];
    }

    ACActionSheet *actionSheet = [[ACActionSheet alloc] initWithTitle:@"" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:mutableArrayTitles.copy actionSheetBlock:^(NSInteger buttonIndex) {
        //        @strongify(self)
//            NSLog(@"ACActionSheet block - %ld",buttonIndex);
        if (buttonIndex == [mutableArrayTitles indexOfObject:@"微信客服"]) {
            UIPasteboard *pastboard = [UIPasteboard generalPasteboard];
            pastboard.string = @"18569802892";
            
            JKAlertView *alertView = [JKAlertView alertViewWithTitle:@"提示：" message:@"微信号已复制到剪切板! 是否跳转到微信?" style:(JKAlertStylePlain)];
            
            [alertView addAction:[JKAlertAction actionWithTitle:@"取消" style:(JKAlertActionStyleCancel) handler:^(JKAlertAction *action) {
                
            }]];
            
            [alertView addAction:[JKAlertAction actionWithTitle:@"确定" style:(JKAlertActionStyleDefault) handler:^(JKAlertAction *action) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"wechat://timeLine"]];
            }]];
            alertView.enableDeallocLog(YES).show().setDismissComplete(^{
                
            });

        }
        if (buttonIndex == [mutableArrayTitles indexOfObject:@"QQ客服"]) {
            NSString *QQ = @"1286278747";
            NSString *url = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",QQ];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
        }
        if (buttonIndex == [mutableArrayTitles indexOfObject:@"客服电话"]) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:18569802892"]];
        }
    }];
    [actionSheet show];
    
}


@end
